﻿using System;

namespace Lesson5_练习题
{
    //定义一个学生类 有5个属性 分别为 姓名 性别 年龄 CS成绩 Unity成绩
    //有两个方法：
    // 1.打招呼：介绍自己的姓名 年龄性别
    // 2.计算自己总分与平均分并显示
    //使用属性完成：年龄必须在0~150之间 成绩必须在0~100之间 性别只能是男或女
    //实例化两个对象并测试
    class Student
    {
        private string name;
        private int age;
        private E_SexType sexType;
        private int csScore;
        private int unityScore;

        public string Name
        {
            get
            {
                return name;
            }
            set
            {
                name = value;
            }
        }
        public int Age
        {
            get
            {
                return age;
            }
            set
            {
                if(value < 0)
                {
                    Console.WriteLine("年龄不能小于0岁，已自动设置为0岁");
                    value = 0;
                }
                else if(value > 150)
                {
                    Console.WriteLine("年龄不能大于150岁，已自动设置为150岁");
                    value = 150;
                }

                age = value;
            }
        }
        public E_SexType SexType
        {
            get
            {
                return sexType;
            }
            set
            {
                if(value != E_SexType.male && value != E_SexType.female)
                {
                    Console.WriteLine("性别只能为男或女，已自动设置为男性");
                    value = E_SexType.male;
                }

                sexType = value;
            }
        }
        public int CsScore
        {
            get
            {
                return csScore;
            }
            set
            {
                if(value < 0)
                {
                    Console.WriteLine("成绩不能小于0，已设置为0");
                    value = 0;
                }
                else if (value > 100)
                {
                    Console.WriteLine("成绩不能大于100，已设置为100");
                    value = 100;
                }
                csScore = value;
            }
        }
        public int UnityScore
        {
            get
            {
                return unityScore;
            }
            set
            {
                if (value < 0)
                {
                    Console.WriteLine("成绩不能小于0，已设置为0");
                    value = 0;
                }
                else if (value > 100)
                {
                    Console.WriteLine("成绩不能大于100，已设置为100");
                    value = 100;
                }
                unityScore = value;
            }
        }

        public void SayHello()
        {
            Console.WriteLine("姓名：{0}，年龄{1}，性别{2}", Name, Age, SexType);
        }

        public void PrintScoreInfo()
        {
            Console.WriteLine("总分：{0}，平均分{1}", CsScore + UnityScore, (float)(CsScore + UnityScore) / 2);
        }
    }

    enum E_SexType
    {
        male,
        female,
        others,
    }
    class Program
    {
        static void Main(string[] args)
        {
            Student s1 = new Student();
            Student s2 = new Student();
            s1.Name = "小明";
            s2.Name = "小红";
            s1.Age = 17;
            s2.Age = 19;
            s1.SexType = E_SexType.male;
            s2.SexType = E_SexType.female;
            s1.CsScore = 78;
            s2.CsScore = 89;
            s1.UnityScore = 93;
            s2.UnityScore = 79;

            s1.SayHello();
            s2.SayHello();
            s1.PrintScoreInfo();
            s2.PrintScoreInfo();
        }
    }
}